package com.library.common.base

import android.view.View
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.kunminx.architecture.ui.callback.UnPeekLiveData
import com.library.common.core.databinding.IntObservableField
import com.library.common.dto.SyetemDto

/**
 * 作者：SimGa
 * 日期：2021/3/6
 * 时间：21:18
 * 包名：com.library.common.base
 */
open class BaseViewModel : ViewModel() {
    //
    val onRetryClick = View.OnClickListener {
        this.onRetry()
    }
    val systemInfo = MutableLiveData<SyetemDto>()

    //显示数据页面
    val statusView = IntObservableField()

    val defUI: UiLoadingChange by lazy { UiLoadingChange() }

    open fun onRetry() {
        defUI.msgEvent.postValue(MessageModel(0))
    }

    /**
     * 内置封装好的可通知Activity/fragment 显示隐藏加载框 因为需要跟网络请求显示隐藏loading配套才加的
     */
    //显示加载框
    inner class UiLoadingChange {
        //请求时loading
        val loading by lazy { UnPeekLiveData<LoadingDialogEntity>() }

        //数据状态类型以及设置
        val msgEvent by lazy { UnPeekLiveData<MessageModel>() }
    }

//    val categoryList = MutableLiveData<List<FirstCategoryDto>>()
//    fun getFirstCatergory() {
//        rxHttpRequest {
//            onRequest = {
//                categoryList.value = getFirstCategory().await()
//            }
//            onError = {
//                XToast.normal(it.msg)
//            }
//        }
//    }
//
//   private fun getFirstCategory(): IAwait<MutableList<FirstCategoryDto>> {
//        return RxHttp.postJson(NetUrl.api_shop_first_category)
//            .add("category", mapOf(Pair("type", "Product")))
//            .toResponse()
//    }
}